import 'package:flutter/material.dart';
import 'package:wan_android_flutter/common/resources/text_styles.dart';

import '../resources/colors/color_data.dart';
import '../resources/spacing.dart';

class CommonLoading extends StatelessWidget {

  final String loadingText;
  final Color? backgroundColor;

  /// 圆圈颜色
  final Color? circleColor;

  /// 弹窗约束
  final BoxConstraints? constraints;

  /// 文本样式
  final TextStyle? style;

  const CommonLoading({
    super.key,
    required this.loadingText,
    this.backgroundColor,
    this.constraints,
    this.circleColor,
    this.style,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      clipBehavior: Clip.hardEdge,
      decoration: BoxDecoration(
        color: backgroundColor ?? ColorData.of(context).bgGray,
        borderRadius: const BorderRadius.all(Radius.circular(8.0)),
        boxShadow: const [
          BoxShadow(
            color: Color(0x57000000),
            blurRadius: 17,
          ),
        ],
      ),
      constraints: constraints ??
          const BoxConstraints(
            maxWidth: 120,
            maxHeight: 120,
            minHeight: 110,
            minWidth: 100,
          ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Spacing.vSpacing2,
          const CircularProgressIndicator(),
          Spacing.vSpacing12,
          Text(
            loadingText,
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
            textAlign: TextAlign.center,
            style: style ?? ColorData.of(context).textBlack.s16.regular,
          ),
        ],
      ),
    );
  }
}
